package org.edu.modules.oa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.SecurityUtils;
import org.edu.common.system.vo.LoginUser;
import org.edu.modules.oa.entity.VeOaMeetEntity;
import org.edu.modules.oa.entity.VeOaMeetUsersEntity;
import org.edu.modules.oa.mapper.IVeOaMeetUsersMapper;
import org.edu.modules.oa.mapper.IVeOaMyApplyMeetMapper;
import org.edu.modules.oa.service.IVeOaMyApplyMeetService;
import org.edu.modules.oa.vo.VeOaMyApplyMeetVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class VeOaMyApplyMeetImpl implements  IVeOaMyApplyMeetService{

    @Resource
    private IVeOaMyApplyMeetMapper iVeOaMyApplyMeetMapper;

    @Resource
    private IVeOaMeetUsersMapper iVeOaMeetUsersMapper;

    @Override
    public HashMap<String, Object> showMyApplyMeet(Integer page, Integer pageSize, VeOaMeetEntity veOaMeetEntity) {
        HashMap<String,Object>map = new HashMap<>();
        // 获取redis存的用户值
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String title = "'%"+veOaMeetEntity.getTitle()+"%'";
        List<VeOaMyApplyMeetVo> myApplyMeetVoList  =iVeOaMyApplyMeetMapper.selectMeetById(page,pageSize,title,veOaMeetEntity.getPlaceId(),"'"+user.getId()+"'");
        int count = iVeOaMyApplyMeetMapper.countApplyMeet(title,veOaMeetEntity.getPlaceId(),"'"+user.getId()+"'");
        // 把查出来的东西存到map里面去
        map.put("list",myApplyMeetVoList);
        map.put("count",count);
        return map;
    }

    @Override
    public String checkUser(Integer id) {
        //创建查询的条件
        QueryWrapper<VeOaMeetUsersEntity>wrapper = new QueryWrapper<>();
        wrapper.eq("meet_id",id);
        //查
        List<VeOaMeetUsersEntity>list = iVeOaMeetUsersMapper.selectList(wrapper);
        String userName = "";
        //iter
        for (VeOaMeetUsersEntity vo : list) {
            userName+= vo.getUserName()+",";
        }
        return userName;
    }


}
